/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "BuddhabrotBase.h"
#include "RandomNumBuffer.h"

class DataBufferDX11;

/**    
    @brief  Compute shader implemention of the Buddhabrot fractal.
    @author yakiimo02
    @date    2010/01/30
*/
class BuddhabrotCS : public BuddhabrotBase
{
public:
    BuddhabrotCS();
    ~BuddhabrotCS();

    HRESULT OnCreateDevice( ID3D11Device* pd3dDevice );
    HRESULT OnResizedSwapChain( ID3D11Device* pd3dDevice, DataBufferDX11* pDataBuffer );
    void    OnFrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
                                  double fTime, float fElapsedTime, DataBufferDX11* pDataBuffer );
    void    OnDestroyDevice();

    inline void SetbClearOutputUAV( const bool bClearOutputUAV ) { m_bClearOutputUAV = bClearOutputUAV; }

protected:
    HRESULT CompileShaders( ID3D11Device* pd3dDevice );
    HRESULT CreateIterationBuffer( ID3D11Device* pd3dDevice );

protected:
    ID3D11ComputeShader*            m_pCS;                    // compute shader
    ID3D11UnorderedAccessView*        m_pOutputUAV;            // uav for buddhabrot render output
    int                                m_nInputWidth;            // buddhabrot texture width
    int                                m_nInputHeight;            // buddhabrot texture height
    int                                m_nOutputWidth;            // buddhabrot texture width
    int                                m_nOutputHeight;        // buddhabrot texture height
    ID3D11Buffer*                    m_pConstantBuf;            // constant buffer for passing parameters

    RandomNumBuffer                    m_randomNumBuffer;        // random number uav, srv and buffer

    bool                            m_bClearOutputUAV;        // clear the output uav
};